package com.neusoft.elmboot.service.impl;

import com.neusoft.elmboot.mapper.BusinessMapper;
import com.neusoft.elmboot.mapper.StarMapper;
import com.neusoft.elmboot.mapper.UserMapper;
import com.neusoft.elmboot.po.Business;
import com.neusoft.elmboot.po.Star;
import com.neusoft.elmboot.service.StarService;
import com.neusoft.elmboot.service.ex.DataNotFoundException;
import com.neusoft.elmboot.service.ex.InsertException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StarServiceImpl implements StarService {

    @Autowired
    private StarMapper starMapper;
    @Autowired
    private BusinessMapper businessMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public int insertStar(Star star) {
        int result = starMapper.insertStar(star);
        if (result < 1) {
            throw new InsertException("收藏失败！");
        }
        return result;

    }

    @Override
    public int deleteStar(Star star) {
       int result = starMapper.deleteStar(star);
         if (result < 1) {
              throw new InsertException("取消收藏失败！");
         }
            return result;
    }

    @Override
    public List<Business> findStarsByUserId(String userId) {
        List<Business> list = starMapper.findStarsByUserId(userId);
        System.out.println("查询到的收藏列表: " + list);
        if(list.isEmpty()){
            throw new DataNotFoundException("您还没有收藏商家！");
        }
        return list;
    }
}
